package com.jsaber.dockerhw.service.impl;

import com.jsaber.dockerhw.mapper.StudentMapper;
import com.jsaber.dockerhw.model.po.Student;
import com.jsaber.dockerhw.model.request.AddStudentRequest;
import com.jsaber.dockerhw.service.SutdentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class SutdentServiceImpl implements SutdentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> getAll() {
        return studentMapper.getAll();
    }

    @Override
    public String insertOne(AddStudentRequest request) {
        Student student = new Student(request);
        return studentMapper.insert(student) == 1 ? "success" : "fail";
    }

    @Override
    public String updateStudent(String stuId, Integer id ){
        Student student = studentMapper.selectByPrimaryKey(id);
        student.setStuId(stuId);
        student.setUpdateTime(new Date());
        return studentMapper.updateByPrimaryKey(student) == 1 ? "success" : "fail";
    }

    @Override
    public String deleteOne(Integer id) {
        return studentMapper.deleteByPrimaryKey(id) == 1 ? "success" : "fail";
    }
}
